﻿using app.Common;
using eService;
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace eService.BLL
{
	public class clsGeneral
	{
		public static string currUserName;
		public static string currFullName;
		public static string currPwd;
		public static string iconWidth;
		public static string iconHeight;
		public static string TimeTypeReport;
		public static string ViewAndPrintBill;
		public static string sqlConnectionString;
		public static int roundValue;
		public static bool MakeBillWhenInput;
		public static bool BillShort;
		public static bool CusVIP;
		public static bool Pause;
		public static bool ShowUserCreate;
		public clsGeneral()
		{
            clsGeneral.sqlConnectionString = ConnectionProvider.ConnString;
			try
			{
                clsGeneral.iconWidth = AppSetting.getSetting().getConfigValue("IconWidth");//ConfigurationSettings.AppSettings["IconWidth"].ToString();
			}
			catch
			{
				clsGeneral.iconWidth = "90";
			}
			try
			{
                clsGeneral.iconHeight = AppSetting.getSetting().getConfigValue("IconHeight"); //ConfigurationSettings.AppSettings["IconHeight"].ToString();
			}
			catch
			{
				clsGeneral.iconHeight = "80";
			}
			try
			{
                clsGeneral.TimeTypeReport = AppSetting.getSetting().getConfigValue("TimeTypeReport");//ConfigurationSettings.AppSettings["TimeTypeReport"].ToString();
			}
			catch
			{
				clsGeneral.TimeTypeReport = "80";
			}
			try
			{
                clsGeneral.ViewAndPrintBill = AppSetting.getSetting().getConfigValue("ViewAndPrintBill");//ConfigurationSettings.AppSettings["ViewAndPrintBill"].ToString();
			}
			catch
			{
				clsGeneral.ViewAndPrintBill = "False";
			}
			try
			{
                clsGeneral.roundValue = int.Parse(AppSetting.getSetting().getConfigValue("RoundValue").ToString());//int.Parse(ConfigurationSettings.AppSettings["RoundValue"].ToString());
			}
			catch
			{
				clsGeneral.roundValue = 1;
			}
			try
			{
                clsGeneral.MakeBillWhenInput = bool.Parse(AppSetting.getSetting().getConfigValue("MakeBillWhenInput").ToString());//ConfigurationSettings.AppSettings["MakeBillWhenInput"].ToString());
			}
			catch
			{
			}
			try
			{
                clsGeneral.BillShort = bool.Parse(AppSetting.getSetting().getConfigValue("BillShort").ToString());//ConfigurationSettings.AppSettings["BillShort"].ToString());
			}
			catch
			{
				clsGeneral.BillShort = false;
			}
			try
			{
                clsGeneral.CusVIP = bool.Parse(AppSetting.getSetting().getConfigValue("CusVIP").ToString());//ConfigurationSettings.AppSettings["CusVIP"].ToString());
			}
			catch
			{
				clsGeneral.CusVIP = false;
			}
			try
			{
                clsGeneral.Pause = bool.Parse(AppSetting.getSetting().getConfigValue("Pause").ToString());//ConfigurationSettings.AppSettings["Pause"].ToString());
			}
			catch
			{
				clsGeneral.Pause = false;
			}
			try
			{
                clsGeneral.ShowUserCreate = bool.Parse(AppSetting.getSetting().getConfigValue("UserCreate").ToString());//ConfigurationSettings.AppSettings["UserCreate"].ToString());
			}
			catch
			{
			}
		}
		public static void SaveLog(string tempUserName, string objectName, string Note)
		{
            SqlConnection con = (SqlConnection)ConnectionProvider.ServerConnection;
            try { if (con.State != ConnectionState.Open)  con.Open(); }
            catch { throw new Exception("Không thể kết nối đến cơ sở dữ liệu"); }

            SqlCommand sqlCommand = new SqlCommand("InsertIntoTabLog", con);
			sqlCommand.CommandType = CommandType.StoredProcedure;
			sqlCommand.Parameters.Add("@EmpID", SqlDbType.VarChar, 50);
			sqlCommand.Parameters.Add("@RoomName", SqlDbType.NVarChar, 200);
			sqlCommand.Parameters.Add("@TimeLog", SqlDbType.DateTime);
			sqlCommand.Parameters.Add("@Note", SqlDbType.NVarChar, 300);
			sqlCommand.Parameters["@EmpID"].Value = tempUserName;
			sqlCommand.Parameters["@RoomName"].Value = objectName;
			sqlCommand.Parameters["@TimeLog"].Value = DateTime.Now;
			sqlCommand.Parameters["@Note"].Value = Note;
			sqlCommand.ExecuteNonQuery();
            con.Close();
            con.Dispose();
		}
		public static double roundMoney(double money, int roundValue)
		{
			double result;
			if (money % (double)roundValue != 0.0)
			{
				result = (double)((int)money / roundValue * roundValue + roundValue);
			}
			else
			{
				result = money;
			}
			return result;
		}
	}
}
